package com.sptus.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sptus.mapper.master.AppEquipmentMapper;
import com.sptus.service.IAppEquipmentService;
import com.sptus.system.domain.DevDictionaries;
import com.sptus.system.domain.Equipment;
import com.sptus.system.domain.vo.AppInfo;
import com.sptus.util.DevSqlUtil;
import com.sptus.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;

@Service
public class AppEquipmentServiceImpl extends ServiceImpl<AppEquipmentMapper, Equipment> implements IAppEquipmentService {

    @Autowired
    JdbcTemplate jdbcTemplate;

    @Override
    public Result<Object> getEquipmentInfo(AppInfo appInfo, Equipment equipment) {
        ArrayList<DevDictionaries> devDictionaries = new ArrayList<>();
        DevDictionaries devDictionaries1 = new DevDictionaries();
        devDictionaries1.setCode("ICT");
        devDictionaries1.setName("市电总有功功率");
        devDictionaries1.setValue("");
        devDictionaries1.setUnit("W");
        devDictionaries1.setRelevanceTable("dev_info_msg0");
        //工作模式
        DevDictionaries devDictionaries2 = new DevDictionaries();
        devDictionaries2.setCode("OPT");
        devDictionaries2.setName("负载总有功功率");
        devDictionaries2.setValue("");
        devDictionaries2.setUnit("W");
        devDictionaries2.setRelevanceTable("dev_info_msg0");
        //AC输出频率
        DevDictionaries devDictionaries3 = new DevDictionaries();
        devDictionaries3.setCode("GFO");
        devDictionaries3.setName("AC输出频率");
        devDictionaries3.setValue(" 55.57");
        devDictionaries3.setUnit("Hz");
        devDictionaries3.setOperation("x/100");
        devDictionaries3.setAnalysis("{\"valid\":\"2\"}");
        devDictionaries3.setRelevanceTable("dev_info_msg0");

        DevDictionaries devDictionaries4 = new DevDictionaries();
        devDictionaries4.setCode("SV1");
        devDictionaries4.setName(" PV1电压");
        devDictionaries4.setOperation("x/10");
        devDictionaries4.setUnit("V");
        devDictionaries4.setRelevanceTable("dev_info_msg0");

        DevDictionaries devDictionaries5 = new DevDictionaries();
        devDictionaries5.setCode("SV2");
        devDictionaries5.setName(" PV2电压");
        devDictionaries5.setOperation("x/10");
        devDictionaries5.setUnit("V");
        devDictionaries5.setRelevanceTable("dev_info_msg0");

        DevDictionaries devDictionaries6 = new DevDictionaries();
        devDictionaries6.setCode("SC1");
        devDictionaries6.setName(" PV1电流");

        devDictionaries6.setUnit("A");
        devDictionaries6.setOperation("x/10");
        devDictionaries6.setRelevanceTable("dev_info_msg0");

        DevDictionaries devDictionaries7 = new DevDictionaries();
        devDictionaries7.setCode("SC2");
        devDictionaries7.setName(" PV2电流");

        devDictionaries7.setUnit("A");
        devDictionaries7.setOperation("x/10");
        devDictionaries7.setRelevanceTable("dev_info_msg0");
        DevDictionaries devDictionaries8 = new DevDictionaries();
        devDictionaries8.setCode("SP1");
        devDictionaries8.setName(" PV1功率");
        devDictionaries8.setValue("78.9");
        devDictionaries8.setUnit("W");
        devDictionaries8.setRelevanceTable("dev_info_msg0");

        DevDictionaries devDictionaries9 = new DevDictionaries();
        devDictionaries9.setCode("SP2");
        devDictionaries9.setName(" PV2功率");

        devDictionaries9.setValue("78.9");
        devDictionaries9.setUnit("W");
        devDictionaries9.setRelevanceTable("dev_info_msg0");

        DevDictionaries devDictionaries10 = new DevDictionaries();
        devDictionaries10.setCode("TI");
        devDictionaries10.setName("逆变器温度");
        devDictionaries10.setValue("35");
        devDictionaries10.setUnit("℃");
        devDictionaries10.setRelevanceTable("dev_info_msg0");

        devDictionaries.add(devDictionaries1);
        devDictionaries.add(devDictionaries2);
        devDictionaries.add(devDictionaries3);
        devDictionaries.add(devDictionaries4);
        devDictionaries.add(devDictionaries5);
        devDictionaries.add(devDictionaries6);
        devDictionaries.add(devDictionaries7);
        devDictionaries.add(devDictionaries8);
        devDictionaries.add(devDictionaries9);
        devDictionaries.add(devDictionaries10);

        DevSqlUtil.DevDataSql(devDictionaries, jdbcTemplate, "96142309600264");
        equipment.setDevDictionaries(devDictionaries);
        Result<Object> result = new Result<>();
        result.setResult(equipment);
        result.success("查询成功");
        return  result;
    }

    @Override
    public Result<Object> getInverterInfo(AppInfo appInfo, Equipment equipment) {
        ArrayList<DevDictionaries> devDictionaries = new ArrayList<>();
        DevDictionaries devDictionaries1 = new DevDictionaries();
        devDictionaries1.setCode("GFI");
        devDictionaries1.setName("市电总有功功率");
        devDictionaries1.setValue("100");
        devDictionaries1.setUnit("Hz");
        devDictionaries1.setRelevanceTable("");

        DevDictionaries devDictionaries2 = new DevDictionaries();
        devDictionaries2.setCode("BV");
        devDictionaries2.setName("电池电压");
        devDictionaries2.setValue("528");
        devDictionaries2.setUnit("V");
        //AC输出频率
        DevDictionaries devDictionaries3 = new DevDictionaries();
        devDictionaries3.setCode("GFO");
        devDictionaries3.setName("AC输出频率");
        devDictionaries3.setValue(" 55.57");
        devDictionaries3.setUnit("Hz");

        DevDictionaries devDictionaries4 = new DevDictionaries();
        devDictionaries4.setCode("SV1");
        devDictionaries4.setName(" PV1电压");
        devDictionaries4.setValue("78.9");
        devDictionaries4.setUnit("V");

        DevDictionaries devDictionaries5 = new DevDictionaries();
        devDictionaries5.setCode("SV2");
        devDictionaries5.setName(" PV2电压");
        devDictionaries5.setValue("78.9");
        devDictionaries5.setUnit("V");

        DevDictionaries devDictionaries6 = new DevDictionaries();
        devDictionaries6.setCode("SC1");
        devDictionaries6.setName(" PV1电流");
        devDictionaries6.setValue("78.9");
        devDictionaries6.setUnit("A");

        DevDictionaries devDictionaries7 = new DevDictionaries();
        devDictionaries7.setCode("SC2");
        devDictionaries7.setName(" PV2电流");
        devDictionaries7.setValue("78.9");
        devDictionaries7.setUnit("A");
        DevDictionaries devDictionaries8 = new DevDictionaries();
        devDictionaries8.setCode("SP1");
        devDictionaries8.setName(" PV1功率");
        devDictionaries8.setValue("78.9");
        devDictionaries8.setUnit("W");
        DevDictionaries devDictionaries9 = new DevDictionaries();
        devDictionaries9.setCode("SP1");
        devDictionaries9.setName(" PV2功率");
        devDictionaries9.setValue("78.9");
        devDictionaries9.setUnit("W");


        devDictionaries.add(devDictionaries1);
        devDictionaries.add(devDictionaries2);
        devDictionaries.add(devDictionaries3);
        devDictionaries.add(devDictionaries4);
        devDictionaries.add(devDictionaries5);
        devDictionaries.add(devDictionaries6);
        devDictionaries.add(devDictionaries7);
        devDictionaries.add(devDictionaries8);
        devDictionaries.add(devDictionaries9);


        equipment.setDevDictionaries(devDictionaries);
        Result<Object> result = new Result<>();
        result.setResult(equipment);

        return result;
    }

    @Override
    public Result<Object> getEquipmentInfoData(AppInfo appInfo, Equipment equipment) {
        ArrayList<DevDictionaries> devDictionaries = new ArrayList<>();
        DevDictionaries devDictionaries1 = new DevDictionaries();
        devDictionaries1.setCode("WFV");
        devDictionaries1.setName("WiFi版本");
        devDictionaries1.setValue("FC41DAAR11A04_RYY.bin_202406041002");
        devDictionaries1.setUnit("");
        devDictionaries1.setRelevanceTable("dev_info_msg3");

        //工作模式
        DevDictionaries devDictionaries2 = new DevDictionaries();
        devDictionaries2.setCode("`FOR`");
        devDictionaries2.setName("额定频率");
        devDictionaries2.setValue("50");
        devDictionaries2.setUnit("Hz");
        devDictionaries2.setRelevanceTable("dev_info_msg3");
        //AC输出频率
        DevDictionaries devDictionaries3 = new DevDictionaries();
        devDictionaries3.setCode("IV");
        devDictionaries3.setName("内部协议版本");
        devDictionaries3.setValue(" 1.0.1");
        devDictionaries3.setUnit("");
        devDictionaries3.setRelevanceTable("dev_info_msg3");

        DevDictionaries devDictionaries4 = new DevDictionaries();
        devDictionaries4.setCode("VOR");
        devDictionaries4.setName(" 额定输出电压");
        devDictionaries4.setValue("1200");
        devDictionaries4.setUnit("V");
        devDictionaries4.setOperation("x/10");
        devDictionaries4.setRelevanceTable("dev_info_msg3");

        DevDictionaries devDictionaries5 = new DevDictionaries();
        devDictionaries5.setCode("VIR");
        devDictionaries5.setName(" 额定输入电压");
        devDictionaries5.setValue("1200");
        devDictionaries5.setUnit("V");
        devDictionaries5.setOperation("x/10");
        devDictionaries5.setRelevanceTable("dev_info_msg3");

        DevDictionaries devDictionaries6 = new DevDictionaries();
        devDictionaries6.setCode("CIR");
        devDictionaries6.setName("额定输入电流");
        devDictionaries6.setValue("500");
        devDictionaries6.setUnit("A");
        devDictionaries6.setOperation("x/10");
        devDictionaries6.setRelevanceTable("dev_info_msg3");

        DevDictionaries devDictionaries7 = new DevDictionaries();
        devDictionaries7.setCode("COR");
        devDictionaries7.setName(" 额定输出电流");
        devDictionaries7.setValue("500");
        devDictionaries7.setOperation("x/10");
        devDictionaries7.setUnit("A");
        devDictionaries7.setRelevanceTable("dev_info_msg3");
//        DevDictionaries devDictionaries8 = new DevDictionaries();
//        devDictionaries8.setCode("SP1");
//        devDictionaries8.setName(" PV1功率");
//        devDictionaries8.setValue("78.9");
//        devDictionaries8.setUnit("W");
//        DevDictionaries devDictionaries9 = new DevDictionaries();
//        devDictionaries9.setCode("SP1");
//        devDictionaries9.setName(" PV2功率");
//        devDictionaries9.setValue("78.9");
//        devDictionaries9.setUnit("W");


        devDictionaries.add(devDictionaries1);
        devDictionaries.add(devDictionaries2);
        devDictionaries.add(devDictionaries3);
        devDictionaries.add(devDictionaries4);
        devDictionaries.add(devDictionaries5);
        devDictionaries.add(devDictionaries6);
        devDictionaries.add(devDictionaries7);
        ArrayList<DevDictionaries> devDictionaries8 = (ArrayList<DevDictionaries>) DevSqlUtil.DevDataSql(devDictionaries, jdbcTemplate, "96142309600264");
        devDictionaries2.setCode("FOR");
//        devDictionaries.add(devDictionaries8);
//        devDictionaries.add(devDictionaries9);

        equipment.setDevDictionaries(devDictionaries8);
        Result<Object> result = new Result<>();
        result.setResult(equipment);

        return result;
    }

    @Override
    public HashMap<String, String> getEquipmentCity(String sn) {

        return this.getBaseMapper().getEquipmentCity(sn);
    }

    @Override
    public List<Equipment> selectListInfo(QueryWrapper<Equipment> equipmentLambdaQueryWrapper) {
        return this.getBaseMapper().selectListInfo(equipmentLambdaQueryWrapper);
    }
}
